package com.meepo.framework.design.grid

import android.view.ViewGroup
import android.widget.RelativeLayout
import androidx.recyclerview.widget.RecyclerView


class GridViewHolder(val mItemView: RelativeLayout) : RecyclerView.ViewHolder(mItemView) {
    fun addChildView(gridItem: GridItem) {

        if (gridItem.backgroundColor != 0) {
            mItemView.setBackgroundColor(gridItem.backgroundColor)
        }

        mItemView.layoutParams = RelativeLayout.LayoutParams(
                gridItem.width,
                gridItem.height
        )

        mItemView.gravity = gridItem.gravity

        if (gridItem.view.parent != null) {
            (gridItem.view.getParent() as ViewGroup).removeView(gridItem.view)
        }

        mItemView.addView(gridItem.view)
    }
}